{include file="header.html"}
<body class="gr">

{if $is_app!=1}
<div class="navBar">
	<a class="left" href="wap.php?app=home&act=index"><i class="return"></i></a>
	<div class="titleView-x">领卷中心</div>
</div>
{/if}

<div class="coupon-list {if $is_app!=1}main-padding-top{/if}">
	<div class="pullRefresh">
		<header class="ge-bottom ge-light">
			<a href="wap.php?app=coupon&act=coupon_list&type=1" {if !isset($type) || $type=='' || $type==1}class="this"{/if}>品牌礼券</a>
			<a href="wap.php?app=coupon&act=coupon_list&type=2" {if isset($type) && $type==2}class="this"{/if}>商品礼券</a>
		</header>
		<ul class="list">
			{foreach from=$data item=g}
			<li class="{if $g->persons/$g->quantity*100>=50 && $g->persons/$g->quantity*100<100}percent50{/if}{if $g->persons/$g->quantity*100==100}percent100{/if}">
				<a href="api.php?app=coupon&act=ling&coupon_id={$g->id}&goalert=领取成功&gourl={urlencode('wap.php?app=coupon&act=coupon_list&type=')}{if isset($type)}{$type}{/if}">
					<div class="right">
						<div class="progress"><span style="width:{number_format($g->persons/$g->quantity*100, 1)}%;"></span></div>
						<div class="percent">已抢{number_format($g->persons/$g->quantity*100, 1)}%</div>
						<div class="btn">立即领取</div>
					</div>
					<div class="left">
						<div>
							<div class="pic" {if $g->pic!=''}style="background-image:url({$g->pic});"{/if}></div>
							<div class="detail">
								<div class="name">{$g->name}</div>
								<div class="coupon-money"><span>{$g->coupon_money}</span>元</div>
								<div class="memo">{$g->min_price_memo}</div>
							</div>
						</div>
					</div>
				</a>
			</li>
			{/foreach}
		</ul>
	</div>
</div>

{include file="footer.html"}

<script>
var offset = $('.pullRefresh .list > li').length;
function createHtml(g){
	var html = '<li class="'+((g.persons.accDiv(g.quantity)*100>=50 && g.persons.accDiv(g.quantity)*100<100)?'percent50':'')+(g.persons.accDiv(g.quantity)*100==100?'percent100':'')+'">\
		<a href="api.php?app=coupon&act=ling&coupon_id='+g.id+'&goalert=领取成功&gourl='+$.urlencode('wap.php?app=coupon&act=coupon_list&type={if isset($type)}{$type}{/if}')+'">\
			<div class="right">\
				<div class="progress"><span style="width:'+(g.persons.accDiv(g.quantity)*100).number_format(1)+'%;"></span></div>\
				<div class="percent">已抢'+(g.persons.accDiv(g.quantity)*100).number_format(1)+'%</div>\
				<div class="btn">立即领取</div>\
			</div>\
			<div class="left">\
				<div>\
					<div class="pic" '+(g.pic!=''?'style="background-image:url('+g.pic+');"':'')+'></div>\
					<div class="detail">\
						<div class="name">'+g.name+'</div>\
						<div class="coupon-money"><span>'+g.coupon_money+'</span>元</div>\
						<div class="memo">'+g.min_price_memo+'</div>\
					</div>\
				</div>\
			</div>\
		</a>\
	</li>';
	offset++;
	return html;
}
$(function(){
	$('header').sticky({ scroller:$('.pullRefresh') });
	$('html, body, .pullRefresh').addClass('height-wrap');
	$('.coupon-list').height($.window().height-$('.coupon-list').padding().top);
	$('.pullRefresh').pullRefresh({
		header : true,
		footer : true,
		footerNoMoreText : '- END -',
		refresh : function(fn){
			var _this = this;
			offset = 0;
			$.getJSON('api.php?app=coupon&act=coupon_list&type={if isset($type)}{$type}{/if}', function(json){
				if(json.error!=0){ $.overloadError(json.msg);return }
				var html = '';
				if($.isArray(json.data))for(var i=0; i<json.data.length; i++)html += createHtml(json.data[i]);
				_this.find('.list').html(html);
				fn();
			});
		},
		load : function(fn){
			var _this = this;
			$.getJSON('api.php?app=coupon&act=coupon_list&type={if isset($type)}{$type}{/if}', { offset:offset }, function(json){
				if(json.error!=0){ $.overloadError(json.msg);return }
				var html = '';
				if($.isArray(json.data))for(var i=0; i<json.data.length; i++)html += createHtml(json.data[i]);
				_this.find('.list').append(html);
				fn();
			});
		}
	});
});
</script>